<?php
// $Id$

/**
 * Controller_Education 控制器
 */
class Controller_Education extends Controller_Prepare
{
    /**
     * 人才培养信息，关于招生信息等
     */
    public function actionIndex()
    {
        // Error handling 初步过滤获得的值，必须满足值类型
        $Gnews_id   = isset($_GET['news_id'])  && is_numeric($_GET['news_id'])  ? $_GET['news_id']  : NULL;
        $Gctgry_id  = isset($_GET['ctgry_id']) && is_numeric($_GET['ctgry_id']) ? $_GET['ctgry_id'] : NULL;

        /**
         * 获取当前显示的新闻
         *
         * @var object $currentNews
         */
        if(isset($Gctgry_id))
        {
            $currentNews = News::find(NewsCategory::genCondition($Gctgry_id))->order(Q::ini('appini/sort'))->query();
        }
      
      if(isset($Gnews_id))
        {
            $currentNews = News::find('news_id = ?', $Gnews_id)->query();
        }

        if(!isset($Gctgry_id) && !isset($Gnews_id))
            // 表示是首页，既无 $_GET['news_id'] 也无 $_GET['ctgry_id']
        {
            $currentNews = News::find('news_id = ?', 375)->query();
            $_GET['ctgry_id'] = 26;
        }

        // Error handling 如果恶意输入不存在的 ctgry_id 或 news_id，导致当前新闻不存在，则显示最新一条新闻
        // Error handling 检查 news_id
        if($currentNews->title == '')
        {
            $currentNews = News::find(NewsCategory::genCondition(26))->order(Q::ini('appini/sort'))->query();
        }
      
      /**
         * 更新当前新闻"阅读"值 hasread = hasread + 1
         */
        News::meta()->updateDbWhere(new QDB_Expr('hasread = hasread + 1'), 'news_id = ?', $currentNews->news_id);

        /**
         * CSS HIGHLIGHT
         *
         * @var string $css
         */
        $css = "a:link[href*='_c{$Gctgry_id}.html'],a:visited[href*='_c{$Gctgry_id}.html']".HIGHLIGHT_CSS_TABS;
        $css .= "a[href*='_{$currentNews->news_id}_']".HIGHLIGHT_CSS;

        $this->_view['currentNews'] = $currentNews;
        $this->_view['css']         = $css;
    }
}